<?php
//=======================================
//###################################
// Kayako Web Solutions
//
// Source Copyright 2001-2004 Kayako Web Solutions
// Unauthorized reproduction is not allowed
// License Number: $%LICENSE%$
// $Author: vshoor $ ($Date: 2006/12/18 19:11:27 $)
// $RCSfile: setup.php,v $ : $Revision: 1.3 $ 
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//
//###################################
//=======================================

if (!defined("INSWIFT")) {
	trigger_error("Unable to process $PHP_SELF", E_USER_ERROR);
}

/**
* Called when the module is to be installed
*/
function _knowledgebase_install($action, $page = '') {
	global $_SWIFT, $__LANG;

	if ($action == "getpages")
	{
		return "1";
	} else if ($action == "buildpage") {
		$_SWIFT["query"]["create"]["kbcategories"] = "CREATE TABLE ". TABLE_PREFIX ."kbcategories (
																				kbcategoryid INT UNSIGNED NOT NULL AUTO_INCREMENT,
																				parentcategoryid INT UNSIGNED NOT NULL DEFAULT '0',
																				staffid INT UNSIGNED NOT NULL DEFAULT '0',
																				title VARCHAR(255) NOT NULL DEFAULT '',
																				dateline INT UNSIGNED NOT NULL DEFAULT '0',
																				totalarticles INT UNSIGNED NOT NULL DEFAULT '0',
																				categorytype ENUM('public', 'private') NOT NULL DEFAULT 'public',
																				displayorder INT UNSIGNED NOT NULL DEFAULT '0',
																				PRIMARY KEY (kbcategoryid),
																				KEY kbcategories1 (parentcategoryid)
																			);";

		$_SWIFT["query"]["create"]["kbarticles"] = "CREATE TABLE ". TABLE_PREFIX ."kbarticles (
																				kbarticleid INT UNSIGNED NOT NULL AUTO_INCREMENT,
																				staffid INT UNSIGNED NOT NULL DEFAULT '0',
																				subject VARCHAR(255) NOT NULL DEFAULT '',
																				isedited SMALLINT(1) UNSIGNED NOT NULL DEFAULT '0',
																				editeddateline INT UNSIGNED NOT NULL DEFAULT '0',
																				editedstaffid INT UNSIGNED NOT NULL DEFAULT '0',
																				views INT UNSIGNED NOT NULL DEFAULT '0',
																				totalcomments INT UNSIGNED NOT NULL DEFAULT '0',
																				hasattachments SMALLINT(1) UNSIGNED NOT NULL DEFAULT '1',
																				dateline INT UNSIGNED NOT NULL DEFAULT '0',
																				displayorder INT UNSIGNED NOT NULL DEFAULT '0',
																				articlestatus ENUM('published', 'draft', 'private') NOT NULL DEFAULT 'published',
																				articlerating FLOAT UNSIGNED NOT NULL DEFAULT '0',
																				ratinghits INT UNSIGNED NOT NULL DEFAULT '0',
																				ratingcount INT UNSIGNED NOT NULL DEFAULT '0',
																				PRIMARY KEY (kbarticleid)
																			);";

		$_SWIFT["query"]["create"]["kbarticledata"] = "CREATE TABLE ". TABLE_PREFIX ."kbarticledata (
																				kbarticledataid INT UNSIGNED NOT NULL AUTO_INCREMENT,
																				kbarticleid INT UNSIGNED NOT NULL DEFAULT '0',
																				contents MEDIUMTEXT,
																				PRIMARY KEY (kbarticledataid),
																				KEY kbarticledata1 (kbarticleid),
																				FULLTEXT (contents)
																			) TYPE=MyISAM;";

		$_SWIFT["query"]["create"]["kbarticlelinks"] = "CREATE TABLE ". TABLE_PREFIX ."kbarticlelinks (
																				kbarticlelinkid INT UNSIGNED NOT NULL AUTO_INCREMENT,
																				kbcategoryid INT UNSIGNED NOT NULL DEFAULT '0',
																				kbarticleid INT UNSIGNED NOT NULL DEFAULT '0',
																				PRIMARY KEY (kbarticlelinkid),
																				UNIQUE KEY (kbcategoryid, kbarticleid),
																				KEY kbarticlelinks1 (kbarticleid)
																			);";

		$_SWIFT["query"]["create"]["kbarticlefiles"] = "CREATE TABLE ". TABLE_PREFIX ."kbarticlefiles (
																				kbarticlefileid INT UNSIGNED NOT NULL AUTO_INCREMENT,
																				kbarticleid INT UNSIGNED NOT NULL DEFAULT '0',
																				filename VARCHAR(255) NOT NULL DEFAULT '',
																				storedfilename VARCHAR(255) NOT NULL DEFAULT '',
																				filesize INT UNSIGNED NOT NULL DEFAULT '0',
																				filetype VARCHAR(150) NOT NULL DEFAULT '',
																				totaldownloads INT UNSIGNED NOT NULL DEFAULT '0',
																				dateline INT UNSIGNED NOT NULL DEFAULT '0',
																				PRIMARY KEY (kbarticlefileid),
																				KEY kbarticlefiles1 (kbarticleid)
																			);";

		$_SWIFT["query"]["insert"]["settings"][0] = "INSERT INTO `". TABLE_PREFIX ."settings`(`section`, `vkey`, `data`) VALUES('registeredmodules', '". MODULE_KNOWLEDGEBASE ."', '1')";
	}
}

/**
* Uninstall Routine
*/
function _knowledgebase_uninstall()
{
	global $_SWIFT;

	$_SWIFT["query"]["drop"]["kbcategories"] = "DROP TABLE `". TABLE_PREFIX ."kbcategories`;";

	$_SWIFT["query"]["drop"]["kbarticles"] = "DROP TABLE `". TABLE_PREFIX ."kbarticles`;";

	$_SWIFT["query"]["drop"]["kbarticledata"] = "DROP TABLE `". TABLE_PREFIX ."kbarticledata`;";

	$_SWIFT["query"]["drop"]["kbarticlelinks"] = "DROP TABLE `". TABLE_PREFIX ."kbarticlelinks`;";

	$_SWIFT["query"]["drop"]["kbarticlefiles"] = "DROP TABLE `". TABLE_PREFIX ."kbarticlefiles`;";

	$_SWIFT["query"]["delete"]["settings"][0] = "DELETE FROM `". TABLE_PREFIX ."settings` WHERE `section` = 'registeredmodules' AND `vkey` = '". MODULE_KNOWLEDGEBASE ."';";
}
?>